<?php
require_once __DIR__ . '/qiniu/autoload.php';

use Qiniu\Auth;

//引入七牛云授权文件
if ($_POST) {
    $roomNumber = $_POST['roomNumber'];
    $userid = $_POST['userid'];

    $accessKey = 'dZ4JiqyNgc6WgVEixLPUSzrEr3jUloZewEuV4gJI';
    $secretKey = 'Intd7MmakuzmxeyY-OeEUPZHWFVaezLArY8Fid_9';
    $auth = new Auth($accessKey, $secretKey);
    $params['appId'] = 'exhjh3b7b';//应用id
    $params['userId'] = $userid;
    $params['roomName'] = $roomNumber;
    $params['permission'] = 'user';
    $params['expireAt'] = time() + 86400;
    $appAccessString = json_encode($params);
    $roomToken = $auth->signWithData($appAccessString);
    if (!empty($roomToken)) {
        $redult['status'] = 'y';
        $redult['info'] = 'roomToken生成成功';
        $redult['data'] = $roomToken;
        exit(json_encode($redult));
    } else {
        $redult['status'] = 'n';
        $redult['info'] = 'roomToken生成失败';
        exit(json_encode($redult));
    }
}
?>
